
function EditJob(uri, statusDisplay, contentPanel) {
  if (!uri)
    uri = EDIT_BASE_PATH + EDIT_JOB_URL;
  statusDisplay = (statusDisplay)?statusDisplay:StatusDisplay.getInstance();
  EditJob._super.call(this, BasePath.get() + uri, statusDisplay);
  this.data = "";
  this.errorMessage = "Could not update changes!";
  this.contentPanel = contentPanel;
}
Object.extend("EditJob", "Job");

EditJob.prototype.onSuccess = function() {
	if (this.onRefresh)
		this.onRefresh();
  else
    this.mergeResponse();
	this._action.close();
	this.statusDisplay.show("changes successfully updated", null, true);
}

EditJob.prototype.mergeResponse = function() {
	if (!this.dom) {
    this.statusDisplay.showError("Invalid DOM for edit success response!", null, true);
    return false;
	}
	this.statusDisplay.show("merging changes...");
	this.contentPanel.merge(this.dom.getElementsByTagName("div")[0]);
	return true;
}

EditJob.prototype.addEntityIdData = function(entity) {
  this.addData("objId", entity.objId);
  this.addData("id", entity.id);
}

EditJob.prototype.executeAction = function(action) {
	this.statusDisplay.show("saving changes...");
	this._action = action;
	this.send(this._getActionData(action)+this.data);
}

EditJob.prototype._getActionData = function(action) {
  var data = "view="+encodeURIComponent(this.contentPanel.getViewUri());
  return data+"&"+action.id+"=1&";
}

EditJob.prototype.addFormData = function(form) {
  EditJob._super.prototype.addFormData.call(this, form);
	var richtextElements = Dom(form).getElementsByClassName("richtext_input");
	for (var i = 0; i < richtextElements.length; ++i) {
		var e = richtextElements[i];
		var dom;
		if (e.iframe) {
			dom = Dom(e.iframe.contentWindow.document.body);
		}
		else {
		  // ignore nested richtext inputs
		  var p = e.parentNode;
		  while ((p != null) && (p != form)) {
		    if (p.className == "richtext_input")
		      break;
		    p = p.parentNode;
		  }
      if ((p != null) && (p != form))
        continue;
			dom = Dom(e);
		}
		this.addData(e.getAttribute("name"), dom.serializeContent());
	}
}


